package com.putable.nmc.world;


import java.io.IOException;
import java.io.StringWriter;
import java.util.InputMismatchException;
import java.util.Scanner;


import junit.framework.TestCase;

public class TestCustomerType
        extends TestCase {

    public static void main(String[] args) {
        junit.textui.TestRunner.run(TestCustomerType.class);
    }

    private String typeLoad;

    protected void setUp() throws Exception {
        super.setUp();
        typeLoad =
            "500 20 50 30 60 40 70 STUDENT wait (weight time)*tasks\n"+
            "200 20 10 30 30 40 30 BIKER wait (weight time)*tasks\n"+
            "75 1 50 1 60 1 70    WORKER wait (weight time)*tasks\n"+
            "300 2 5 2 6 2 7    RETIREE wait (weight time)*tasks\n";
    }
    
    public void testComplainProb() {
        assertEquals(0.00,CustomerType.STUDENT.getComplainProbability());
        assertEquals(0.10,CustomerType.BIKER.getComplainProbability());
        assertEquals(0.25,CustomerType.WORKER.getComplainProbability());
        assertEquals(0.80,CustomerType.RETIREE.getComplainProbability());
    }

    public void testRead() {
        try {
            CustomerType.readInfo(new Scanner(typeLoad));
            // If that didn't throw, that test's passed..

            // Let's make sure save/read is idempotent
            StringWriter sw1 = new StringWriter();
            CustomerType.saveInfo(sw1);
            CustomerType.readInfo(new Scanner(sw1.toString()));

            StringWriter sw2 = new StringWriter();
            CustomerType.saveInfo(sw2);
            assertEquals(sw1.toString(), sw2.toString());
        } catch (InputMismatchException e) {
            fail("Parse error");
        } catch (IOException e) {
            fail("IO exception");
        }
    }
}
